package com.nCoV.EpidemicSurveillance.controller;


import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.nCoV.EpidemicSurveillance.domain.AreaReach;
import com.nCoV.EpidemicSurveillance.domain.CxArea;
import com.nCoV.EpidemicSurveillance.domain.PatientAreaRelation;
import com.nCoV.EpidemicSurveillance.domain.PatientTrainRelation;
import com.nCoV.EpidemicSurveillance.domain.Person;
import com.nCoV.EpidemicSurveillance.domain.TrainNode;
import com.nCoV.EpidemicSurveillance.scheduled.Sjfx;
import com.nCoV.EpidemicSurveillance.scheduled.Tjfx;
import com.nCoV.EpidemicSurveillance.service.DataEntryService;

/**
 * @author 罗穆健
 * @date 2020年3月9日
 */
@RequestMapping("entry")
@Controller
public class DataEntryController {
	
	@Autowired
	DataEntryService dataEntryService;

	@RequestMapping(value="createorquery")
	@ResponseBody
	public Map<String, Object> createOrQuery(@RequestParam("patientName")String name,
			@RequestParam("IDCard")String idCard) {
//		System.out.println(name + " " + idCard);

		return dataEntryService.createOrQuery(name, idCard);
	}
	
	@RequestMapping(value="setmsg")
	@ResponseBody
	public Map<String, Object> setMsg(@RequestParam("patientName")String name,
			@RequestParam("IDCard")String idCard,
			@RequestParam("address")String address,
			@RequestParam("age")String age,
			@RequestParam("sex")String sex,
			@RequestParam("jcbNum")String jcbNum,
			@RequestParam("phone")String phone,
			@RequestParam("email")String email,
			@RequestParam("jcNum")String jcNum,
			@RequestParam("grgl")String grgl,
			@RequestParam("zlqk")String zlqk,
			@RequestParam("glqk")String glqk) {
		if("1".equals(grgl)) {
			grgl = "1.0";
		}
		return dataEntryService.setMsg(name,idCard,address,age,sex,jcbNum,phone,email,jcNum,grgl,zlqk,glqk);
	}
	
	@RequestMapping(value="createrelation")
	@ResponseBody
	public Map<String, Object> createRelation(
			@RequestParam("patientIdCard")String patientIdCard,
			@RequestParam("contactorName")String contactorName,
			@RequestParam("contactorIdCard")String contactorIdCard,
			@RequestParam("contactTime")String contactTime,
			@RequestParam("contactName")String contactName,
			@RequestParam("duration")String duration,
			@RequestParam("tfqk")String tfqk,
			@RequestParam("kzqk")String kzqk,
			@RequestParam("dfkz")String dfkz){
		
		return dataEntryService.createRelation(patientIdCard,contactorName,contactorIdCard,
				contactTime,contactName,duration,tfqk,kzqk,dfkz);
	}
	
	@RequestMapping(value="getrelation")
	@ResponseBody
	public List<Map<String, Object>> getRelationByIdCard(@RequestParam("patientIdCard")String patientIdCard,
			@RequestParam("skip")String skipNum,
			@RequestParam("limit")String limitNum,
			@RequestParam("searchData")String searchData){
//		System.out.println(skipNum+" "+limitNum);
		return dataEntryService.getRelationByIdCard(patientIdCard,skipNum,limitNum,searchData,searchData);
		
	}
	
	@RequestMapping(value="getxqrelation")
	@ResponseBody
	public Map<String, Object> getXqRelationByIdCard(
			@RequestParam("patientIdCard")String patientIdCard,
			@RequestParam("contactorIdCard")String contactorIdCard,
			@RequestParam("contactName")String contactName){
		return dataEntryService.getXqRelationByIdCard(patientIdCard,contactorIdCard,contactName);
		
	}
	
	@RequestMapping(value="deleterelation")
	@ResponseBody
	public Map<String,Object> deleteRelationByIdCard(
			@RequestParam("patientIdCard")String patientIdCard,
			@RequestParam("contactorIdCard")String contactorIdCard,
			@RequestParam("contactName")String contactName,
			@RequestParam("createDay")String createDay) {
		return dataEntryService.deleteRelationByIdCard(patientIdCard, contactorIdCard,contactName,createDay);
	}
	
	@RequestMapping(value = "addnewarea")
	@ResponseBody
	public Map<String, Object> addNewArea(AreaReach areaReach,PatientAreaRelation patientAreaRelation,
			@RequestParam("patientIdCard")String patientIdCard){
		return dataEntryService.addNewArea(areaReach,patientAreaRelation,patientIdCard);
	}
	
	@RequestMapping(value = "getarearelation")
	@ResponseBody
	public List<Map<String, Object>> getAreaRelationByIdCard(@RequestParam("patientIdCard")String patientIdCard,
			@RequestParam("skip")int skipNum,
			@RequestParam("limit")int limitNum,
			@RequestParam("searchAreaData")String searchAreaData) {
		return dataEntryService.getAreaRelationByIdCard(patientIdCard,skipNum,limitNum,searchAreaData);
	}
	
	@RequestMapping(value = "deletearearelation")
	@ResponseBody
	public Map<String,Object> deleteAreaRelationByIdCard(
			@RequestParam("patientIdCard")String patientIdCard,
			@RequestParam("contactName")String contactName,
			@RequestParam("xqAddress")String xqAddress,
			@RequestParam("addressName")String addressName) {
		return dataEntryService.deleteAreaRelationByIdCard(patientIdCard,addressName, xqAddress,contactName);
	}
	
	@RequestMapping(value="createTrainRelation")
	@ResponseBody
	public Map<String, Object> createTrainRelation(@RequestParam("patientIdCard")String patientIdCard,
			TrainNode trainNode, PatientTrainRelation patientTrainRelation){
		return dataEntryService.createTrainRelation(patientIdCard,trainNode,patientTrainRelation);
		
	}
	
	@RequestMapping(value="gettrafficrelation")
	@ResponseBody
	public List<Map<String, Object>> getTrafficRelation(@RequestParam("patientIdCard")String patientIdCard,
			@RequestParam("skip")int skipNum,
			@RequestParam("limit")int limitNum,
			@RequestParam("searchTrafficData")String searchTrafficData){
				return dataEntryService.getTrafficRelation(patientIdCard,skipNum,limitNum,searchTrafficData);
		
	}
	
	@RequestMapping(value="deleteNode")
	@ResponseBody
	public Map<String, Object> deleteNode(@RequestParam("id")Long id){
				return dataEntryService.deleteNode(id);
		
	}
	
	@RequestMapping(value="deletetrafficrelation")
	@ResponseBody
	public Map<String, Object> deleteTrafficRelation(@RequestParam("relationId")Long relationId){
		return dataEntryService.deleteTrafficRelation(relationId);
	}
	
	@RequestMapping(value="updatedtraffic")
	@ResponseBody
	public Map<String, Object> updatedTraffic(PatientTrainRelation patientTrainRelation,
			@RequestParam("trafficId")Long trafficId){
		return dataEntryService.updatedTraffic(patientTrainRelation,trafficId);
	}
	
	@RequestMapping(value = "updateArea")
	@ResponseBody 
	public Map<String, Object> updateArea(@RequestParam("areaId")Long areaId,
			@RequestParam("relationId")Long relationId,
			@RequestParam("addressName")String addressName,
			@RequestParam("xqAddress")String xqAddress,
			@RequestParam("reachTime")String reachTime,
			@RequestParam("leaveTime")String leaveTime,
			@RequestParam("tfqk")String tfqk,
			@RequestParam("kzqk")String kzqk){
		return dataEntryService.updateArea(areaId,relationId,addressName,xqAddress,reachTime,leaveTime,tfqk,kzqk);
		
	}
	
	@RequestMapping(value = "updatePerson")
	@ResponseBody 
	public Map<String, Object> updatePerson(@RequestParam("patientIdCard")String patientIdCard,
			@RequestParam("contactorIdCard")String contactorIdCard,
			@RequestParam("contactName")String contactName,
			@RequestParam("contactTime")String contactTime,
			@RequestParam("contactorPhone")String contactorPhone,
			@RequestParam("duration")String duration,
			@RequestParam("tfqk")String tfqk,
			@RequestParam("kzqk")String kzqk,
			@RequestParam("dfkz")String dfkz){
		return dataEntryService.updatePerson(patientIdCard,contactorIdCard,contactName,contactTime,contactorPhone,
				duration,tfqk,kzqk,dfkz);
	}
	
	@RequestMapping(value = "getDrjcNode")
	@ResponseBody 
	public List<Map<String, Object>> getDrjcNode(){
		return tjfx.getDrjcNode();
	}
	
	@Autowired
	Sjfx sjfx;
	@RequestMapping(value = "test")
	@ResponseBody 
	public void test(){
		sjfx.sjcl();
	}
	
	@Autowired
	Tjfx tjfx;
	@RequestMapping(value = "test1")
	@ResponseBody 
	public void test1(){
		tjfx.tjfx();
	}
	@RequestMapping(value = "test2")
	@ResponseBody 
	public void test2(){
		tjfx.scRelation();
	}
	
	@RequestMapping(value = "test3")
	@ResponseBody 
	public void test3(){
		sjfx.clccqfq();
	}
	
	@RequestMapping(value = "test4")
	@ResponseBody 
	public void test4(){
		tjfx.tjChengShi();
	}
	

}
